<template>
    <div>
        <el-table :data="$store.getters['role/getRoleList']" border style="width: 100%">
            <el-table-column prop="id" label="角色编号" width="180">
            </el-table-column>
            <el-table-column prop="rolename" label="角色名称" width="180">
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="item">
                    <div>
                        <!-- {{ item.row.status }} -->
                        {{ item.row.status == 1 ? '启用' : '禁用' }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" size="small" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { mapGetters } from 'vuex';
import { roleDelete } from '../../request/api';
export default {
    data() {
        return {

        }
    },
    methods: {
        // 删除单条数据
        del(id) {
            this.$confirm('确定要删除此数据么?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                roleDelete({ id }).then(res => {
                    if (res.code == 200) {
                        // 删除成功
                        console.log(res);
                        this.$message.success(res.msg);
                        // 重新渲染视图
                        this.$store.dispatch('role/getRoleListActions')
                    } else {
                        // 删除失败
                        this.$message.success(res.msg);

                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 修改数据
        edit(id) {
            console.log(id, '修改');
            this.$emit('edit', id);
        }


    },
    mounted() {
        // 进入页面就调用角色列表
        this.$store.dispatch('role/getRoleListActions')

    },
    watch: {},
    computed: {},
    filters: {},
    components: {},
}
</script>
<style scoped></style>